


/*
*************************************************************************
*西瑞克斯研发管理系统
*版 本: 1.0   
*日 期：03/05/2012    
*作 者： 王浩 QQ：873987060   
*************************************************************************   
*/  
package com.application.yfsmsrecord.dao;
import java.util.List;
import java.util.ArrayList;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Session;
import com.manager.commons.page.PageBean;
import org.apache.log4j.Logger;
import com.manager.commons.dao.HibernateGenericDao;
import com.manager.commons.page.PageBean;
import com.application.yfsmsrecord.entity.YfSmsrecord;
import com.application.yfsmsrecord.struts.form.YfSmsrecordForm;
 /**
 * 
 * Description:YfSmsrecordDAO<br />
 * 
 * Version:V0.1<br />
 * 
 * Author: 王浩 QQ：873987060 <br />
 * 
 * History: <br />
 * 
 * 03/05/2012 
 * 
 */
public class YfSmsrecordDAO extends HibernateGenericDao<YfSmsrecord>
{
    private static final Logger logger = Logger.getLogger(YfSmsrecordDAO.class);

	private YfSmsrecord yfSmsrecord;

	public YfSmsrecord getYfSmsrecord() {
		return this.yfSmsrecord;
	}

	public void setYfSmsrecord(YfSmsrecord yfSmsrecord) {
		this.yfSmsrecord = yfSmsrecord;
	}

	public Integer getAllCountYfSmsrecord(YfSmsrecordForm yfSmsrecordForm){
	    List args = new ArrayList();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT COUNT(0) FROM yf_smsrecord WHERE 1=1 ");
                sql = getStringBuffer(yfSmsrecordForm,sql,args);
		return super.getCount(sql.toString(),args.toArray());
	}
        
	public void deleteYfSmsrecords(YfSmsrecordForm yfSmsrecordForm){    	
    		String hql = " delete from YfSmsrecord where id in  ( " + yfSmsrecordForm.getIds() + ")";
		Session session = this.getSession();
		try
		{
			session.createQuery(hql).executeUpdate();
		}
		catch(RuntimeException re)
		{
		        logger.error("deleteYfSmsrecords failed");	
			throw re;
		}
		finally
		{
			if (session != null)
			{
				releaseSession(session);
			}
		}
       }

	public List searchYfSmsrecord(YfSmsrecordForm yfSmsrecordForm,PageBean pageBean){  
	    List args = new ArrayList();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT * FROM yf_smsrecord WHERE 1=1 ");
		sql = getStringBuffer(yfSmsrecordForm,sql,args);
		return getPageInfo(pageBean,sql.toString(),args);
	}
	
	public void updateStatus(int id,Long state){  
	    List args = new ArrayList();
		StringBuffer sql = new StringBuffer();
		sql.append(" update yf_smsrecord set state= "+state+" where id =" + id);
        super.execute(sql.toString());
	}
	

	/**
	 * 查询条件的封装 
	 * @param departmentForm 
	 * @return
	 */
	private StringBuffer getStringBuffer(YfSmsrecordForm yfSmsrecordForm,StringBuffer buf,List args){
		/* 需要加入查询条件时封装
		*/
		
           		                
				if(null != yfSmsrecordForm.getBussType() && yfSmsrecordForm.getBussType().longValue() != 0){
	     	buf.append(" and BUSS_TYPE = ? ");
			args.add(yfSmsrecordForm.getBussType());
		}
		                
		
                						if(StringUtils.isNotBlank(yfSmsrecordForm.getBussId())){
		    buf.append(" and BUSS_ID like ? ");
			args.add("%" + yfSmsrecordForm.getBussId().trim() + "%");
		}
                						if(StringUtils.isNotBlank(yfSmsrecordForm.getReceNo())){
		    buf.append(" and RECE_NO like ? ");
			args.add("%" + yfSmsrecordForm.getReceNo().trim() + "%");
		}
                						if(StringUtils.isNotBlank(yfSmsrecordForm.getReceUser())){
		    buf.append(" and RECE_USER like ? ");
			args.add("%" + yfSmsrecordForm.getReceUser().trim() + "%");
		}
                				                
		                
				if(StringUtils.isNotBlank(yfSmsrecordForm.getStartSendTime())){
		    buf.append(" and SEND_TIME >= ? ");
			args.add(yfSmsrecordForm.getSendTime());
		}
		if(StringUtils.isNotBlank(yfSmsrecordForm.getEndSendTime())){
			buf.append(" and SEND_TIME <= ? ");
			args.add(yfSmsrecordForm.getSendTime());
		}
		
                						if(StringUtils.isNotBlank(yfSmsrecordForm.getSendContent())){
		    buf.append(" and SEND_CONTENT like ? ");
			args.add("%" + yfSmsrecordForm.getSendContent().trim() + "%");
		}
                						if(StringUtils.isNotBlank(yfSmsrecordForm.getWorkitmeId())){
		    buf.append(" and WORKITME_ID like ? ");
			args.add("%" + yfSmsrecordForm.getWorkitmeId().trim() + "%");
		}
                						if(StringUtils.isNotBlank(yfSmsrecordForm.getOrg())){
		    buf.append(" and ORG like ? ");
			args.add("%" + yfSmsrecordForm.getOrg().trim() + "%");
		}
                				                
				if(null != yfSmsrecordForm.getSendType() && yfSmsrecordForm.getSendType().longValue() != 0){
	     	buf.append(" and SEND_TYPE = ? ");
			args.add(yfSmsrecordForm.getSendType());
		}
		                
		
                						if(StringUtils.isNotBlank(yfSmsrecordForm.getOperateid())){
		    buf.append(" and OPERATEID like ? ");
			args.add("%" + yfSmsrecordForm.getOperateid().trim() + "%");
		}
                				                
		                
				if(StringUtils.isNotBlank(yfSmsrecordForm.getStartCreateDate())){
		    buf.append(" and CREATE_DATE >= ? ");
			args.add(yfSmsrecordForm.getCreateDate());
		}
		if(StringUtils.isNotBlank(yfSmsrecordForm.getEndCreateDate())){
			buf.append(" and CREATE_DATE <= ? ");
			args.add(yfSmsrecordForm.getCreateDate());
		}
		
                				return buf;
	}
	
}
	